import numpy as np

# 准备数据集
# np.random.seed(1)
X = np.random.rand(100, 1)
y = 4 + 3 * X + np.random.randn(100, 1)
X_b = np.c_[np.ones((X.shape[0], 1)), X]

# 超参数
num_iterations = 10000000

t0, t1 = 5, 500


def learning_rate_schedule(t):
    return t0 / (t + t1)


theta = np.random.randn(2, 1)

# train
for i in range(num_iterations):
    gradients = X_b.T.dot(X_b.dot(theta) - y)
    learning_rate = learning_rate_schedule(i)
    theta = theta - learning_rate * gradients

print(theta)
